package com.midea.ai.air.ui.home.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.common.ConsVal;
import com.midea.ai.air.utils.JumpUtils;
import com.midea.ai.air.view.BottomDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ouyangdi on 2016/4/6.
 * 编辑房间->房间设置Fragment
 */
public class EditRoomSetFragment extends BaseFragment implements View.OnClickListener{
    private String mStrRoom;
    private EditText mEditRoomName;
    private RelativeLayout mLayoutSceneBtn;
    private RelativeLayout mLayoutDeviceManager;
    private ImageView mIvSwitchScene;
    private boolean mIsSceneOn = false;
    private TextView mTvDeleteRoom;

    //底部弹窗相关
    BottomDialog mBotDialog;

    public void setStrRoom(String strRoom) {
        mStrRoom = strRoom;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_edit_room_set, container, false);
        initViews(view);

        return view;
    }

    private void initViews(View view) {
        mEditRoomName = (EditText)view.findViewById(R.id.edit_room_name);
        mEditRoomName.setHint(mStrRoom);

        mIvSwitchScene = (ImageView)view.findViewById(R.id.scene_button_switch);
        mIvSwitchScene.setOnClickListener(this);

        mLayoutSceneBtn = (RelativeLayout)view.findViewById(R.id.layout_scene_button);
        mLayoutSceneBtn.setOnClickListener(this);

        mLayoutDeviceManager = (RelativeLayout)view.findViewById(R.id.layout_device_manage);
        mLayoutDeviceManager.setOnClickListener(this);

        mTvDeleteRoom = (TextView)view.findViewById(R.id.tv_delete_room);
        mTvDeleteRoom.setOnClickListener(this);

        List<BottomDialog.ListItem> mItems = new ArrayList<>();
        mItems.add(new BottomDialog.ListItem(getResources().getString(R.string.air_home_edit_room_delete_room), getResources().getColor(R.color.red_text_color)));
        //初始化底部Dialog
        mBotDialog = new BottomDialog(getActivity()).builder().addListItems(mItems);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.scene_button_switch:
                if(mIsSceneOn) {
                    mIvSwitchScene.setImageResource(R.drawable.more_setting_location_bt_off);
                    mIsSceneOn = false;
                    return;
                }
                mIvSwitchScene.setImageResource(R.drawable.more_setting_location_bt_on);
                mIsSceneOn = true;
                break;

            case R.id.layout_scene_button:
                JumpUtils.toPage(getActivity(),getResources().getString(R.string.air_home_edit_room_scene),
                        getResources().getString(R.string.air_home_edit_room), ConsVal.ACTIVITY_TAG_EDIT_ROOM_SET_SCENE);
                break;

            case R.id.layout_device_manage:
                JumpUtils.toPage(getActivity(), getResources().getString(R.string.air_home_edit_room_device_manage),
                        "", ConsVal.ACTIVITY_TAG_EDIT_ROOM_DEVICE);
                break;

            case R.id.tv_delete_room:
                mBotDialog.show();
                break;

            case R.id.btn_delete_room:
                break;
        }
    }
}
